package com.example.testapplication;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;

/**
 * @author wwq on 2019/7/19  10:40.
 */
public class NetBroadcastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        //得到网络连接状态
        ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        //得到网路连接
        NetworkInfo info = manager.getActiveNetworkInfo();

        if (info.isConnected()) {
            Toast.makeText(context, "有网络连接", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(context, "无网络连接", Toast.LENGTH_SHORT).show();
        }

    }

}
